#ifndef RAYCI_BEAM_QUALITY_H
#define RAYCI_BEAM_QUALITY_H

#include <QImage>
#include "../RayCiLut.hpp"
#include "QString"
#include <QObject>
#include <vector>
#include "../BeamQuality/BeamQualityTypes.h"


class Beam_Quality : public QObject {
Q_OBJECT

signals:
    void getBeamQualityDataS();
    void BeamQualitySequenceRefreshed(const QVector<QString>& itemInfos, const QVector<bool>& itemChecked);;
public slots:
    void exportReport();


private:

     CurrentPlaneParams calculateBeamEllipseParameters(double dSecondMomentXX_mm, double dSecondMomentXY_mm, double dSecondMomentYY_mm) const;

     QString getIsoConformityString(int docId, bool (*getIsoConformityFunc)(int, char*, int*)) const;

     template<typename T>
     QString getParameterValue(int docId, bool (*isValidFunc)(int, bool, bool*),
                             bool (*getValueFunc)(int, bool, T*),
                             bool withUncertainty = false) const;

     template<typename T>
     std::pair<QString, QString> getParameterWithUncertainty(int docId,
        bool (*isValidFunc)(int, bool, bool*),
        bool (*getValueFunc)(int, bool, T*)) const;

    bool m_isProcessing = false;
    bool m_isSaving = false;

public:
    int _iBeamQualityDocId = 0;
    double BeamQualityWavelength = 0.0;
    double BeamQualityFocalLength = 0.0;
    QVector<QPair<QImage,std::vector<float>>> m_beamQualityResultsImage;
    QVector<char>ResultImageVis;
    BeamQualityDataBatch m_batchData;

    void stopBeamQuality();
    void clearBeamQuality();
    void setFrameSpan(int frame);
    int getTimeSpan();
    void setTimeSpan(double dTime);
    void setSingleShot(bool bSingleShot);
    void getBeamQualityData();

    // 图像压缩与保存相关方法
    bool isValid() const;
    bool isModified() const;
    QString getPathName() const;
    bool isProcessing() const;
    bool isSaving() const;

    // 图像处理操作
    bool cropToAOI(double dExtraOuterArea = 0.0);
    bool binning2x2();

    // 保存操作
    bool saveDocument();
    bool saveAsDocument(const QString& filePath);

    // 状态检查
    bool checkProcessingStatus();


    double getLaserWavelength();
    double getFocalLength();
    void setLaserWavelength(double dWavelength);
    void setFocalLength(double dWavelength);
    QString getRecordingRemark() const;

    int getMeasureMethodIndex() const;
    bool getRawBeamMeasureResult() const;
    void setBeamQualityMethod(int index);
    void setBeamQualityRawBeamResult(bool IsRawBeamResult);

    void setLinkStart(bool bLink);
    void setLinkStop(bool bLink);
    CurrentPlaneParams getCurrentBMParams(int index);
    BeamQualityResult getBeamQualityResult() ;
    // void savebeamqualityresult();

    int getItemCount() const;
    QString getItemInfo(int index) const;
    bool getItemEnabled(int index) const;
    void setCurrentItem(int index) const;
    void setItemEnabled(int index,bool checked) const;
    void setItemMoveUp(int index) const;
    void setItemMoveDown(int index) const;
    void setItemRemove(int index) const;
    void setItemSort() const;
    void setItemRefresh() ;


    void close(bool bWaitWhileClosing);
    void clear();

};

#endif //RAYCI_BEAM_QUALITY_H